﻿using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using ResxHelper.Object;

namespace ResxHelper.Logic.Writers
{
    public class ResourceFileAndroidFormatter : IResourceFileFormatter
    {
        public ResourceFile InputFile { get; private set; }

        public ResourceFileAndroidFormatter(ResourceFile input)
        {
            InputFile = input;
        }

        public string Run()
        {
            var doc = new XDocument(new XElement("resources", GetEntriesElements(InputFile.Entries)));
            return doc.ToString();
        }

        private static IEnumerable<XElement> GetEntriesElements(ResourceFileEntryCollection entries)
        {
            return entries.Select(e =>
                new XElement("string",
                    new XAttribute("name", e.Key), e.Value));
        }
    }
}
